Skip to content

feat: Set last_used time upon account sign in#3408

Merged
lmuntaner merged 21 commits intomainfrom
arshvair/update-last-used-account-tiemstamps
Oct 19, 2025
Merged

feat: Set last_used time upon account sign in#3408
lmuntaner merged 21 commits intomainfrom
arshvair/update-last-used-account-tiemstamps

Conversation

@aterga
Copy link
Copy Markdown
Collaborator

@aterga aterga commented Oct 10, 2025

Motivation

According to the latest design, users who enable multiple accounts should see their accounts in the order in which they were last used. This requires that the order of usage is recorded on the Internet Identity backend, since otherwise the order cannot be known across the multiple devices that a user may have.

The storage as well as the canister API already supported last_used field, but it was not being populated.

To that end, this PR:

  1. Prepares the code for recording last_used timestamps, slightly refactoring the storage code to bring about more clarity.
  2. Starts populating the field.

Changes

  • Add a new function with_account_mut that enables writing storage code for editing account details with a single account lookup (rather than one lookup to check if it exists, then another lookup to actually edit the account and record the changes).
  • Add a new function set_account_last_used to Storage, call it from prepare_account_delegation.
  • Call set_account_last_used account last used in prepare_account_delegation of the account management modules to populate the field when a delegation is created.

Tests

  • Integration tests to check the new field is populated as expected.
  • Unit test for the new storage method.
  • Current unit and integration tests are enough to test that the refactor didn't change the expected behavior.

@aterga aterga force-pushed the arshvair/update-last-used-account-tiemstamps branch from b0037e1 to 6b2c993 Compare October 13, 2025 14:20
@aterga aterga marked this pull request as ready for review October 13, 2025 14:38
@aterga aterga requested a review from lmuntaner October 13, 2025 14:43
@aterga aterga changed the title Arshvair/update last used account tiemstamps chore: Factor out the functionality for editing details of a single account Oct 13, 2025
* save

* first

* Fix tests

* second

* Fix tests

* first

* Move last_used update to prepare_account_delegation

* save-2

* Fix some issues from the parent PR

* Apply suggestion from @aterga

* Apply suggestion from @aterga

* fix
@aterga aterga changed the title chore: Factor out the functionality for editing details of a single account chore: Set last_used time upon account sign in Oct 13, 2025
@aterga aterga changed the title chore: Set last_used time upon account sign in feat: Set last_used time upon account sign in Oct 13, 2025
@lmuntaner lmuntaner force-pushed the arshvair/update-last-used-account-tiemstamps branch from b4d5f9a to d7d08f6 Compare October 17, 2025 06:34
@lmuntaner lmuntaner force-pushed the arshvair/update-last-used-account-tiemstamps branch from b9d2aa8 to 3d8d3b2 Compare October 17, 2025 07:43
@lmuntaner lmuntaner requested a review from sea-snake October 17, 2025 08:19
Copy link
Copy Markdown
Contributor

@sea-snake sea-snake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Those additional tests clear up the questions I had.

@lmuntaner lmuntaner added this pull request to the merge queue Oct 19, 2025
Merged via the queue into main with commit 0808bc3 Oct 19, 2025
77 checks passed
@lmuntaner lmuntaner deleted the arshvair/update-last-used-account-tiemstamps branch October 19, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants